Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic API client for tests #921

Merged
merged 1 commit into from
Nov 15, 2023
Merged

Dynamic API client for tests #921

merged 1 commit into from
Nov 15, 2023

Conversation

gunndabad
Copy link
Collaborator

Until now we've used a single fixed API client ID (and key) in our API tests. Now we're adding roles (and want to use various role combinations in tests) we need a more dynamic mechanism.

This introduces a TestAuthenticationHandler similar to what we use in other test projects. There's a singleton CurrentApiClientProvider that's shared by the server and tests that allows setting the current user ID. (It's an AsyncLocal to allow concurrent tests to set their own user independently.)

Given we have two authentication schemes in the API - the API key plus an ID access token - we have to know when our test handler should run vs when it shouldn't (we don't want this TestAuthenticationHandler kicking in when we're testing endpoints that require an ID access token). To do that, I've added a header to the HttpClient used for API key-based calls; the authentication handler looks for that before it runs.

@gunndabad gunndabad force-pushed the dynamic-api-client-in-tests branch from 87d9f6d to 9007337 Compare November 15, 2023 12:55
@gunndabad gunndabad force-pushed the dynamic-api-client-in-tests branch from 9007337 to a786752 Compare November 15, 2023 12:55
@MrKevJoy MrKevJoy self-requested a review November 15, 2023 12:56
@gunndabad gunndabad enabled auto-merge (squash) November 15, 2023 13:01
@gunndabad gunndabad merged commit 050f0fd into main Nov 15, 2023
11 checks passed
@gunndabad gunndabad deleted the dynamic-api-client-in-tests branch November 15, 2023 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants